package com.liu.sx.controller;

import com.liu.sx.common.entity.Result;
import com.liu.sx.common.status.CodeEnum;
import com.liu.sx.entity.User;
import com.liu.sx.service.UserService;
import org.aspectj.apache.bcel.classfile.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping
public class IndexController {

    @Autowired
    private UserService userService;

    @PostMapping("/login")
    @ResponseBody
    public Result login(@RequestBody User user){


     return new Result(true, CodeEnum.OK.getCode(),"success",user);
    }

    @PostMapping("/app/login")
    @ResponseBody
    public Result appLogin(@RequestBody User user){

         User   login =userService.findByName(user.getName());
         if(login.getPassword().equals(user.getPassword())){
             return new Result(true, CodeEnum.OK.getCode(),"success",login);
         }else {
             return new Result(true, CodeEnum.ACCESS_ERROR.getCode(),"用户名或者密码不正确");
         }


    }


    @GetMapping("/")
    public String index(){

       return  "index";
    }

    @GetMapping("/task/list")
    public String taskList(){

        return  "task/list";
    }

    @GetMapping("/driver/list")
    public String driverList(){

        return  "driver/list";
    }
    @GetMapping("/driverlogin/list")
    public String driverloginList(){

        return  "driverlogin/list";
    }

    @GetMapping("/wrom/list")
    public String wromList(){

        return  "wrom/list";
    }

    @GetMapping("/voltage/list")
    public String voltageList(){

        return  "voltage/list";
    }

    @GetMapping("/pay/list")
    public String payList(){

        return  "pay/list";
    }


}
